use crate::class::Class;
use crate::native_library::{NativeLibrary, NativeMethod};
use std::collections::HashMap;

#[derive(Default)]
pub struct Registry {
    pub(crate) classes: HashMap<String, Class>,
    pub(crate) native_library: NativeLibrary,
}

impl Registry {
    pub fn add_class(&mut self, class: Class) -> &mut Self {
        self.classes.insert(class.this_class.to_string(), class);
        self
    }

    pub fn class(&self, name: &str) -> &Class {
        &self.classes.get(name).expect(&*format!(
            "java.lang.ClassNotFoundException: {}",
            name.replace("/", ".")
        ))
    }

    pub fn native_method(&self, name: &str) -> &NativeMethod {
        &self.native_library[name]
    }
}
